package pers.xukai.common.service.impl;

import cn.hutool.core.bean.BeanUtil;
import org.springframework.stereotype.Service;
import pers.xukai.common.entity.po.User;
import pers.xukai.common.entity.vo.RegisterUserVo;
import pers.xukai.common.repository.UserRepository;
import pers.xukai.common.service.UserCommonService;

import java.util.Date;

@Service
public class UserCommonSerivceImpl implements UserCommonService {
    private final UserRepository userRepository;

    public UserCommonSerivceImpl(UserRepository userRepository) {
        this.userRepository = userRepository;
    }

    /**
     * 注册用户
     *
     * @param registerUserVo
     */
    @Override
    public void registerUser(RegisterUserVo registerUserVo) {
        registerUserVo.check();
        User user = new User();
        BeanUtil.copyProperties(registerUserVo, user);
        user.setCreateUser("admin");//todo createUser暂时写死，后期再请求中读取当前用户
        user.setCreateTime(new Date());
        user.setIsEnable(user.getIsEnable() != null && user.getIsEnable());
        user.setIsLock(user.getIsLock() != null && user.getIsLock());
        userRepository.save(user);
    }
}
